Repository navigation
Fix Inbox attention and operation pagination before work - #9169
loopx-agent wants to merge 3 commits into
Conversation
Preserve the existing proposal and both signed review fixes. Qualify the same Inbox behavior against the current Lark and Chat integration. Signed-off-by: LoopX Agent <[email protected]>
Signed-off-by: LoopX Agent <[email protected]>
Signed-off-by: LoopX Agent <[email protected]>
loopx-agent
left a comment
There was a problem hiding this comment.
Reviewer: model_agent · Gemini · Google DeepMind · self_reported
Approval conclusion (author-owned PR; GitHub blocks formal self-approval)
动机 / Motivation
在受管 Turn 开始前执行 manager-inbox read 的 Agent,如果收件箱里积压着多条“已交付部分结论但仍有后续工作”的请求或大量未结外发委派,过去每轮都会被迫在未读/已交付之间重复吞吐完整的原始长简报,同时一旦触发操作交接分页溢出,还会把未分页完的外发摘要或跨模式 --operation-cursor 搞丢。在基线 ab4654b8fca5 上,turn_start_hook 默认渲染不带过滤参数的 manager-inbox read:即使某条收件的当前版本已有经过回执验真的部分结论(remaining_work),整份原始 brief 仍保留在 items 里反复输出;同时外发请求只在 unfinished_delegations 有限窗口中截取,而一旦操作交接页溢出并带入 --operation-cursor 翻页,_pending_result 在页内条目已完成记录且缺少 --attention-only 游标对齐时无法稳定续页,更危险的是 Peer 回传的 .delivery.json 过去未绑定请求 ID 与结果键,容易把同作用域别的请求/结果的送达回执误当成当前请求的折叠凭证。
本次在 17688838ee 上线的改动让 turn_start_hook 默认以 --attention-only 调用 manager-inbox read:仍待读取原简报的请求继续完整留在 items;当前修订版已通过确切消息哈希或精确 Peer (goal_ref/requester/recipient, request_id, result_key) 送达回执验真的部分结论请求则折叠进 open_request_summaries 保留 remaining_work 以便追踪,随时仍可通过不带 --attention-only 的 --request-id 取回原文;同一请求游标 next_cursor 在读完收件后无副作用地续读外发请求摘要,而操作交接游标 operation_handoff_next_cursor 固定使用 pending_requests_v1 作用域,支持在默认与 --attention-only 模式间无缝续页;缺少绑定或作用域冲突的 Peer 回执拒绝折叠并在授权重读时修补或报错。本 PR 不改变默认不带 --attention-only 的 manager-inbox read 全量输出语义,不支持在精确 --request-id、original_conversation_v0 通道或 status 子命令上使用 --attention-only,不自动消费或重发任何 Peer 结果,也未在本机 macOS 环境复现 Windows SQLite 宿主退出清理与官方安装版 Desktop/飞书真机端到端链路。
改动思路 / Approach
若仅仅依赖提示词让模型自己跳过长简报,模型在多轮续办时仍会先被完整上下文淹没;反过来若在 Python 展示层按正文关键词猜测“已交付”后再做裁剪,又会在队列尚在排队、回复 JSON 损坏或 Peer 回执被跨请求串用时误删原始要求。因此本方案:以 TypeScript 事务层 inbox_read.ts 作为收件折叠规则、游标域划分和 Peer 回执绑定身份的单一决策所有者,把结果消息哈希计算抽成共享辅助函数 returnMessageId 供发送与读取双端复用,而 Python 适配层(peers.py、inbox.py、manager_inbox.py、manager_context/__init__.py)仅透传标记、校验 CLI 参数互斥并按独立游标续拉操作交接,不在 Python 侧复制折叠逻辑。当前 PR 边界覆盖 Manager Inbox 收件箱的注意模式分页、操作交接游标跨模式续读、Peer 送达回执精确绑定以及配套的 EN/ZH 参考文档和回归测试,不修改 turn_start_hook 原本的 loopx_cli_argv() 路由策略,也不扩展原生子代理结果分页或控制面外发权限模型。
- 三条正交状态边界:
- 收件折叠 vs 完整保底:
deliveredRemainderSummary只在state.kind === "awaiting_conclusion"且存在remaining_work、无活跃控制保留位、读回执可读、linksReceipt有效且当前修订版最新conclusion确为status === "delivered"时才折叠进open_request_summaries;待投递队列(queued)、损坏/冲突回执与缺失或旧版未绑定的 Peer 回执一律退回完整items。 - 双向分离又兼容的两个游标域:收件/外发分页游标在注意模式下先走
pending_attention_v2再切换到pending_outgoing_v1,与全量模式的pending_requests_v1严格隔离,防止跨模式误用--cursor;而operation_handoff_next_cursor始终以pending_requests_v1写入_cursor_scope,无论在--attention-only、默认模式还是仅含外发摘要的续页上都能接着--operation-cursor继续翻页,且在_outgoing_continuation续页上不写入读/交付/消费回执。 - Peer 送达回执严格身份绑定:
recordReads对新建或升级的.delivery.json强制写入request_id与result_key(配合原有goal_ref或requester/recipient),且升级缺少request_id的旧回执时不继承原model_turn与delivered_at;冲突的request_id或result_key立即抛出作用域不匹配错误并保持原文件字节不动。
- 收件折叠 vs 完整保底:
具体改动 / Changes
- 规范基线与逐条映射:对照变更前不可变基线
docs/reference/required-work-context.md(spec_revision:ab4654b8fca5b2538d42588134b8f8aef4a32fe6)以及随 PR 同步更新的manager_context/README.md与required-work-context.mdEN/ZH 段落逐条核对:REQ-bounded-attention-fold(implemented):--attention-only仅把有当前修订版已送达部分结论的收件摘要进open_request_summaries,未结原始要求、队列态及损坏/冲突项保留在items,且不带--attention-only的--request-id可无损重读全文(inbox_read.ts:210-291)。REQ-cross-mode-operation-cursor(implemented):operationCursorScope固定复用pending_requests_v1,_pending_result在携带--operation-cursor时即便请求页已完成也照常拉取后续操作交接,支持在注意模式、普通模式及组合游标下续读(inbox_read.ts:247-262、inbox.py:224-243)。REQ-exact-peer-delivery-binding(implemented):partialDeliveryMatches与recordReads通过peerDeliveryScope+request_id+result_key精确校验并升级绑定 Peer 回执,拦截跨请求或错结果键复用(inbox_read.ts:394-406, 590-618)。REQ-outgoing-read-safety(implemented):外发摘要续页(outgoingSummaryPage/outgoingContinuation)跳过返还投递采集、recordReads与unfinished_delegations冗余投影,只读交付摘要(inbox_read.ts:494-513, 699-704、peers.py:726-787)。
关键代码讲解
deliveredRemainderSummary与pendingPage(inbox_read.ts:210-291):先经receiptState、linksReceipt与agendaResults校验当前请求修订版是否真实处于已交付部分结论态,再决定折叠为open_request_summaries还是保留完整inboxItem;同时分出operationCursorScope = scopeFor("pending_requests_v1")与pending_attention_v2/pending_outgoing_v1,并在入站条目读尽后无缝衔接到outgoingSummaryPage。peerDeliveryScope、partialDeliveryMatches与recordReads(inbox_read.ts:394-406, 590-618):当请求类型为peer且回执kind === "requester_cli_read"时要求显式匹配request_id与result_key;bound判断旧回执是否已有request_id,升级旧回执时刷新观测时间与绑定键而不沿用陌生 Turn,若现有request_id或result_key冲突则 fail-closed 拒绝覆写。returnMessageId(result_publication.ts:20-24、return_delivery.ts:19):将原有确定性handoff.<sha256>消息身份构造从return_delivery.ts抽取并复用给inbox_read.ts校验本地 Manager 交付,消除重复实现与序列化空格漂移风险。_pending_result、read_inbox与handle_manager_inbox(inbox.py:224-243、peers.py:701-787、manager_inbox.py:267-271、manager_context/__init__.py:295):CLI 层拒绝--attention-only与--request-id或非read动作混用;turn_start_hook为标准入口加上--attention-only;peers.py与inbox.py在外发续页跳过消费回执写操作,并在携带operation_cursor时保留操作交接分页返回。
本 PR 共修改 12 个文件(+520 / -95 行):生产代码 7 个文件(TypeScript inbox_read.ts、result_publication.ts、return_delivery.ts 与 Python manager_inbox.py、manager_context/__init__.py、inbox.py、peers.py),测试 3 个文件与文档 2 个文件;无新增守护进程或权限入口。
对主干的风险 / Risks
- 非阻塞本地测试环境观察(PATH 解析顺序):
turn_start_hook(manager_context/__init__.py:288)沿用主干既有的*loopx_cli_argv()渲染裸命令loopx ... --attention-only,而tests/test_delegation_turn_context.py(如第 179、242、641 行)直接在子进程执行该渲染命令。当未将 worktree 的.venv/bin放到PATH前面而直接运行.venv/bin/python -m pytest时(相当于不通过uv run),子进程会命中环境里旧版~/.local/bin/loopx并报错unrecognized arguments: --attention-only(10 个用例失败);只要按规范经PATH="<venv>/bin:$PATH"/uv run执行即全部通过(30 passed, 2 skipped)。此 CLI 路由沿用主干既有策略,本次未引入新退化。 - 反例与独立端到端验证:
- 真机流式对比(drain 前 vs drain 后 vs exact read vs outgoing 续页):用
roundtrip.flow实测同一条含BIG_ORIGINAL_CONTEXT与remaining_work的请求,在drain投递前(仍处于 queued)manager-inbox read --attention-only保留在items且open_request_summaries=[](Markdown10,806B);经drain写入确切message_id送达回执后再增发 1 条新收件与 1 条外发 Peer 请求,注意模式将其折叠进open_request_summaries(Markdown 仅10,383B,原长上下文不泄露),通过--request-id可完整还原原文,--cursor外发续页(JSONITEMS=0, OUT_SUMM=1, MUTATED=False;Markdown5,308B完整保留外发 ID)不改写任何.json回执。 - 否定选择器与回执篡改:CLI 实测
--attention-only --request-id与status --attention-only均以 exit 1 明确拒绝;TS 测试与 Pythontest_before_work_reader_requires_exact_peer_delivery实测旧无绑定回执、跨请求first_receipt与错result_key均保持全文留在items且字节不被篡改,read_inbox遇到冲突绑定直接抛出peer return delivery receipt scope mismatch。 - 跨模式游标与与最新
main预合并校验:将 PR 精确 head17688838ee与最新origin/main(202d7bdb054b)本地无冲突合并(包含docs/reference/required-work-context.md自动合并),在合并树上实测 4 个 TypeScript 核心套件70 passed、test_chat_operation_actions.py+test_delegation_turn_context.py73 passed, 2 skipped。
- 真机流式对比(drain 前 vs drain 后 vs exact read vs outgoing 续页):用
- 提示文本义务核对(
decision_text_assessment):新增ATTENTION_GUIDANCE、turn_start_hook--attention-only及 EN/ZH 文档均明确告知遇到入站摘要须用不带--attention-only的--request-id读全文、含仅摘要页也需沿next_cursor追完、外发续页不交付/消费结果,未削弱安全或验收义务。 - 验证矩阵与范围:
- TypeScript 控制面 4 个协作套件:70 passed, 0 failed(PASS)。
- TypeScript
tsc --project tsconfig.control-plane.json --noEmit:0 errors(PASS)。 - Python
tests/test_delegation_turn_context.py(.venv/bin在 PATH):30 passed, 2 skipped(2 个 PowerShell 用例在 macOS 跳过)(PASS)。 - 周边 10 个 Python 协作/上下文测试文件:285 passed(PASS)。
- 与当前
origin/main(202d7bdb054b)本地合并验证:TS 70 passed + Python 73 passed, 2 skipped(PASS)。 ruff check、mypy(17 文件)、canary premerge --tier quick:全部通过(PASS)。- 远端托管 CI 未作阻塞等待(
wait_for_ci=false;PR 原托管运行曾报 Windows SQLite 隔离运行时退出报错及main已有的 Ark/Pages 基线问题),安装版 Desktop App 与真实飞书通道未在本轮本地测试。
我的整体评价 / Verdict
本 PR 对 long_horizon 与 user_experience 均判定为 improved:在不改动默认全量读取与任何授权边界的前提下,使托管长程 Turn 在收件箱多条部分结论和大量外发交接并存时仍保留关键剩余工作、可跨模式续完操作交接分页,并堵住了 Peer 送达回执跨请求误折叠的漏洞。visual_review 为 not_applicable(已核对全部 12 个改动文件,均属控制面 TS、CLI/协作 Python、测试与参考文档,无前端或 Lark 视图改动,unverified_scope 为 none)。
本次改动在既有的 inbox_read.ts、result_publication.ts 和 Python 协作适配边界内完成,新增的 open_request_summaries 复用既有的 Turn 委派项投影结构,与当前 origin/main(202d7bdb054b)预合并全部核心 TS/Python 验证通过;未发现阻塞性问题,提醒在后续清理测试辅助环境或排查 Windows 托管 SQLite 退出时可顺带收敛。
English verdict: APPROVE — Exact-head review on 1768883 passes with zero blocking findings. Defaulting before-work reads to --attention-only folds only revision-verified delivered partial conclusions into open_request_summaries, preserves cross-mode --operation-cursor paging under pending_requests_v1, binds peer delivery receipts by request_id and result_key, and passes 70 TS + 30+285 Python tests plus origin/main merge verification (ruff, kernel mypy, tsc, and quick premerge PASS).
|
This pull request has merge conflicts with Choose the remote for the base repository, not an out-of-date fork. git fetch upstream
git rebase upstream/main
# Resolve each conflict, git add the resolved files, then git rebase --continue.
git push --force-with-lease origin HEADFor a same-repository clone whose Keep the DCO |
loopx-agent
left a comment
There was a problem hiding this comment.
Reviewer: model_agent · gpt-6.2-sol · OpenAI · runtime_reported · xhigh
Approval conclusion (author-owned PR; GitHub blocks formal self-approval)
动机 / Motivation
持续处理委派的 Agent 每轮都要核对未完工作的当前要求。 未完的部分交付和仍待验真的请求过去均可能在首个 Inbox 视图重复全文。 原先常规 before-work 读会重复交付已经读过的完整简报。现在,已验证当前修订和具体结果的部分交付进入摘要,仍保留剩余工作。待送达或回执不确定的请求继续交付全文,摘要可用原 request ID 取回完整简报。 现在的必读命令选择 --attention-only,按已验证结果的状态决定摘要。请求游标读完收到的工作后继续外发摘要,操作交接游标仍可独立续读。 本轮复验真实 File/SQLite 源码 CLI 和协作事务。Windows、正式安装版和实时 Feishu 留作单独验收。
改动思路 / Approach
将摘要选择、游标和回执绑定放在现有 TypeScript 事务中,Python 继续传递类型化选项和展示数据。 摘要保留剩余工作和原请求 ID。原始要求仍由 --request-id 入口供依赖工作前核验。 继续使用现有完整收件、精确请求、返回消息和操作游标,保留可追溯的摘要资格。
具体改动 / Changes
准确头 1768883,merge base ab4654b,12 个文件,+520/-95。当前主干 a6ffb3b 只在 tests/test_delegation_turn_context.py 的测试助手定义附近有冲突。我在临时集成树中保留主干 output_limit 参数及此提案对 --attention-only 的断言。临时树的 7 项聚焦用例覆盖当前主干 64,000 字节声明和原生保底两支、精确回执及游标。 按修订 1768883 的仓库规范核对各项要求。 目标规范
- attention-full-and-summary · Only a verified current partial result permits summary output; the full brief is always recoverable.
- independent-operation-cursor · Resume operations across modes while continuing incoming and outgoing request pages independently.
- exact-delivery-recovery · Tie each partial delivery to its specific request and exact result; recover unknown facts without loss.
- declared-host-integration · Preserve the current main Inbox reader budget when calling the generated attention mode.
关键代码讲解
- 按回执生成摘要 核对当前修订的最新已交付结论。
- 请求和操作游标 分开请求读取模式与操作页作用域。
- 精确结果绑定 核对请求、结果和送达来源,并保留异常回执供恢复。
- 合规读回的旧回执 重新确立可追溯的当前绑定。
对主干的风险 / Risks
精确头通过 73 项 Python(2 项 PowerShell 跳过)、28 项 TypeScript 和相对分叉基线的本地 quick premerge。原生 CLI 正向核对了同一简报完整与摘要入口、独立操作游标和外发请求继续读取。 本地反例验证旧无绑定、错误请求和错误结果回执均保留全文与原回执,只有以原结果合法读回后才恢复摘要。外发续页无交付、消费或读回执写入。其他 Agent 的游标被拒绝。 临时集成树只处理测试助手的冲突,生产代码沿 Git 的自动合并结果。其 7 项聚焦用例通过。 当前 GitHub 分支的测试冲突需要作者处理,重新发布后的提交需要复验和新头评审。
我的整体评价 / Verdict
批准当前准确头的实现。下一步可合并两侧的测试断言,并在新头复验真实的 before-work 命令、主干声明的读取预算,以及只读的外发与操作续页。GitHub 当前分支仍有源文件冲突。
English verdict: APPROVE at 1768883. Approve this exact implementation. The native before-work tests preserve exact brief recovery, result identity, and independent cursor boundaries. A local integration preserving both test semantics passes seven focused cases against current main. The GitHub head still has a test-source merge conflict.
Supersedes #9013. The two signed commits start at
ab4654b8fca5b2538d42588134b8f8aef4a32fe6onmain. The review covers the 12-file Inbox change and the pagination repair in the previous review.Restore unfinished delegation work
The existing before-work Inbox read now provides compact summaries for incoming requests whose current revision has a verified, delivered partial conclusion. Other incoming requests retain their full brief. The request cursor continues into unfinished sent requests, and exact request reads remain available. Sent-only pages perform no result delivery or consumption.
An operation cursor issued by the attention view can now resume with the standard
manager-inbox read --operation-cursorcommand advertised by the overflow response. It uses the existing Goal and Agent scope in either Inbox view. The request cursor still depends on the selected view. Both cursors can advance in one read, and the existing receiver read validates that a partial delivery belongs to the current reply before compacting it.Bind peer delivery to the exact result
The Inbox keeps the full brief when a peer delivery receipt cannot prove the request ID and result key. A read of the exact result records both fields in the existing receipt. That read establishes delivery for an older unbound receipt with the current observation time and Turn. A receipt with conflicting identity stays visible for recovery.
Verification for
17688838eefe92e982a81f787507304375906e63mainb3961047f1f4981cc601e6bd06c6f5808fad5c2epassed, including the bilingual and public-boundary checks.f55bb4456ca7c714565c324337dc451ea2528ac0, with the reviewed head as its second parent. The wheel SHA-256 is6a1acb82f6fed09adab4f97a2e60a1de660774a5b14f5bfba1c1cea0b49cb5dc. Release Artifacts · Candidate artifacttest_managed_start_interruption_preserves_reservation_and_attempt[initial_before-file]failed at the same cadence assertion on both the hosted merge commit and its first parent00ef1c79ae5dfed0dfc4681968ee12369b510345. Frontstage Pages · Optional Ark TurnHosted Windows follow-up
618074cpassed all nine SQLite CLI tests on Windows. The latest run from Fix live and queued steering in private Steward conversations #9185 also passed the same nine cases on Windows. Both used Node 22.22.3. Earlier merge tree · Latest comparison618074c, the failed Windows merge treef55bb44, and its first parent00ef1c7. The two merge trees have identical SQLite tests, runtime shutdown code, and cleanup fixture. This narrows the independent repro to Windows cleanup on the reported run. GitHub reported that the workflow was still running and declined a targeted retry. The exact-head Windows failure remains open.Integration with current main
The reviewed head
1768883merged locally with main at5e2c896. The integrated tree passed 78 focused Python cases, 163 TypeScript cases, and the control-plane type check. Two additional cases passed on the native Codex app-server with an isolated home and a loopback provider. They exercised saved-context recovery and explicit CLI routing. Two PowerShell cases and eight other opt-in native variants remain untested in this run.Main then advanced to
717924d. The new integrated tree passed 310 cases across the chat operation, compact identifier, and content digest suites. The reviewed PR head is unchanged. Chat action refactorStrict MkDocs passed on the first integrated tree with the standalone runtime-guide fix applied, including the rendered Inbox pagination and receipt documentation. GitHub still shows the failed Windows check and six pending Python shards on the original run. Pages fix · Original Python workflow
Native Codex before-work read
The hosted candidate wheel ran the generated before-work Inbox command in two consecutive Turns of one native Codex app-server thread on each of the File and SQLite providers. The first read kept the full brief for the request whose receipt named the wrong result. The requester read rejected that conflict. In a controlled legacy-receipt case, the authorized requester read restored the exact request and result binding. The second native Turn then showed both compact summaries and kept the remaining work visible. The only stored change from the native reads was the expected receiver read marker for the full brief.
The test used Codex
0.171.0-alpha.13, an isolated workspace and a loopback inference provider. The workspace-scoped fixture could create its own guard lock and reach the local TypeScript effect runtime. The read-only and network-disabled variants reported permission errors for the lock and the connection respectively. Official App, live Feishu and hosted CI qualification remain open.Native Inbox pagination with a new request between reads
The same hosted wheel ran the generated before-work reads in two native Turns on each of the isolated File and SQLite providers. The first page showed 20 of 23 requests. A request arrived before the saved cursor's position. The original cursor still returned the remaining three entries without duplicates, and a fresh read recovered all 24 original briefs, including the new request. Using the cursor for a different Agent returned an explicit scope error and wrote no read receipts. The original captured page still matched its recorded SHA-256 after the new request arrived.
The native tool truncated three large page responses per provider even though the commands exited successfully. The test detected the UTF-8 byte gap and reread the same capture from the same offset with a 4,000-byte page and 5,000-byte output limit. All bytes matched the original digest before the page was accepted. This validated recovery in the isolated host. The default native tool output limit still affected larger pages.
Verification for the previous head
048484cff255367eb7cb2710792ca917d577acc0. With the Inbox changes reapplied to current main, the new regression assertion detected a different operation cursor for the same position before the fix. After the fix, the default, attention-only, and combined reads all return the same two remaining operations. The test also checks Agent scope rejection and that these reads leave the operation store unchanged.test_chat_operation_actions.pyandtest_delegation_turn_context.pypassed 72 cases. Two PowerShell cases were skipped. Coverage includes consecutive guards, File and SQLite, and host envelopes and native file delivery.618074c7763e0d23cbaa5d154e253e1462676d7a, whose second parent is the candidate head above. The candidate wheel SHA-256 isf09546030bea0d3288937bb86707d4e8c908ce3136e01c9c5c9cef222f368330.Frontstage Pages failed its strict documentation build on the relative runtime guide link from
docs/reference/protocols/turn-envelope-v0.md. The same strict build failed with that single warning on the PR base and candidate. The linked document and source link are identical at those revisions.